package com.smart.campus.web.controller.student;

import java.util.List;

import com.smart.campus.school.domain.ApproveList;
import com.smart.campus.school.domain.Student;
import com.smart.campus.school.service.IApproveListService;
import com.smart.campus.school.service.IStudentService;
import com.smart.campus.web.utils.StudentUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.ApplyList;
import com.smart.campus.school.service.IApplyListService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 学生请假申请Controller
 * 
 * @author Zhihe.Li
 * @date 2020-06-15
 */
@Controller
@RequestMapping("/student/apply")
public class StudentApplyListController extends BaseController
{
    private String prefix = "student/apply";

    @Autowired
    private IApplyListService applyListService;
    @Autowired
    private IApproveListService approveListService;

    @Autowired
    private IStudentService studentService;

    @GetMapping()
    public String apply()
    {
        return prefix + "/apply";
    }

    /**
     * 查询学生请假申请列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ApplyList applyList)
    {
        startPage();
        applyList.setStudentId(StudentUtil.getStudentId());
        List<ApplyList> list = applyListService.selectApplyListList(applyList);
        return getDataTable(list);
    }

    /**
     * 新增学生请假申请
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        Student student = StudentUtil.getStudentInfo();
        modelMap.put("student",student);
        return prefix + "/add";
    }

    /**
     * 新增保存学生请假申请
     */
    @Log(title = "学生请假申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ApplyList applyList)
    {

        return toAjax(applyListService.insertApplyList(applyList));
    }

    /**
     * 修改学生请假申请
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ApplyList applyList = applyListService.selectApplyListById(id);
        mmap.put("applyList", applyList);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生请假申请
     */
    @Log(title = "学生请假申请", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ApplyList applyList)
    {
        return toAjax(applyListService.updateApplyList(applyList));
    }


    /**
     * 修改学生请假申请
     */
    @GetMapping("/getApproveList/{id}")
    public String getApproveList(@PathVariable("id") Long id, ModelMap mmap)
    {
        ApplyList applyList = applyListService.selectApplyListById(id);

        mmap.put("applyList", applyList);
        return prefix + "/approveList";
    }

}
